package edu.neusoft.yuejian_09.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import edu.neusoft.yuejian_09.R;
import edu.neusoft.yuejian_09.adapter.ClubActAdapter;
import edu.neusoft.yuejian_09.bean.Activities;
import edu.neusoft.yuejian_09.model.ClubModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class ClubActActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private TextView c_name;
    private ImageView btn_left;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_club_act);
        initViews();
        initEvents();
        initData();

    }

    //初始化控件
    public void initViews() {
        btn_left = (ImageView) findViewById(R.id.left);
        recyclerView = (RecyclerView) findViewById(R.id.club_activity);
        c_name = (TextView) findViewById(R.id.club_name);

    }

    //基本事件
    public void initEvents() {
        btn_left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }


    //获取数据
    public void initData() {

        getClubactivitys();
    }


    private void getClubactivitys() {
        Bundle bundle = this.getIntent().getExtras();
        String c_id = bundle.getString("club_id");
        Log.d("userbg", "club_id");
        System.out.print(c_id);
        ClubModel clubModel = new ClubModel();//diaoyong
        Call call = clubModel.getClubactivitys(c_id);
        call.enqueue(new Callback<List<Activities>>() {
            @Override
            public void onResponse(Call<List<Activities>> call, Response<List<Activities>> response) {
                List<Activities> activity = response.body();
                // mDataList = (List) response.body();
                recyclerView.setAdapter(new ClubActAdapter(ClubActActivity.this, activity));
            }

            @Override
            public void onFailure(Call<List<Activities>> call, Throwable t) {
                Toast.makeText(ClubActActivity.this, "fail", Toast.LENGTH_SHORT).show();
            }
        });

    }
}





